﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EntityBinder.Interface
{
	/// <summary>
	/// Interface to define requirements for IEntityElement.
	/// </summary>
	public interface IEntityElement
	{
		/// <summary>
		/// Identifier of the element, it could be the key in a json file or the name of the xml tag.
		/// </summary>
		string Identifier { get; set; }

		/// <summary>
		/// True if this element is optional and is not mandatory found while reading files.
		/// </summary>
		bool Optional { get; set; }

		/// <summary>
		/// Binder to use to read / write the object.
		/// </summary>
		IBinder Binder { get; set; }

		/// <summary>
		/// Collection of children related to this element.
		/// </summary>
		IEnumerable<IEntityElement> Children { get; }

		/// <summary>
		/// Add a child to the list.
		/// </summary>
		/// <param name="_child">The child to add.</param>
		void AddChild(IEntityElement _child);

		/// <summary>
		/// Add children to the list.
		/// </summary>
		/// <param name="_children">children to add.</param>
		void AddChildren(params IEntityElement[] _children);

		/// <summary>
		/// Remove a child from the list.
		/// </summary>
		/// <param name="_child">The child to remove.</param>
		void RemoveChild(IEntityElement _child);

		/// <summary>
		/// Remove a child at a specified index.
		/// </summary>
		/// <param name="_childIndex">The index of the child to remove.</param>
		void RemoveChild(int _childIndex);

		/// <summary>
		/// Remove all the children of this element.
		/// </summary>
		void RemoveAllChildren();

		/// <summary>
		/// Read data from file and bind it to the source container.
		/// </summary>
		/// <param name="_source">Container for data.</param>
		/// <param name="_contentValue">Content read from file.</param>
		/// <returns>The data object created and nested in source.</returns>
		object Read(object _source, string _contentValue);

		/// <summary>
		/// Write data to a file through the IElementWriter object.
		/// </summary>
		/// <param name="_source">Data to write.</param>
		/// <param name="_writer">The provider to write data.</param>
		void Write(object _source, IElementWriter _writer);
	}
}
